package com.bang.study.util;

import java.lang.reflect.Method;

/**
 * @Auther: Bang
 * @Date: 2019/9/21 23:11
 * @Description: 性能测试工具类
 */
public class TestUtil {

    public static void test(Class clazz, Integer[] arr) {
        Object instance = null;
        try {
            instance = clazz.newInstance();

            Method sort = clazz.getDeclaredMethod("sort", Integer[].class);
            sort.setAccessible(true);
            long startTime = System.nanoTime();
            sort.invoke(instance, (Object) arr);
            long endTime = System.nanoTime();
            double time = (endTime - startTime) / 1000000000.0;
            System.out.println(String.format("%s 消耗时间: %s S ,数据量: %s", clazz.getSimpleName(), time, arr.length));
            System.out.println();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
